<template>
	<view>
		
		<view class="portrait_box" @tap="openImg1">
			<image :src="src" mode="scaleToFill"></image>
		</view>
		<view class="set_title">基本资料</view>
		
		<view class="list_box">
			<view class="title">昵称</view>
			<input type="text" value="" placeholder="请输入"  v-model="name"/>
		</view>

		
		
		
		
		<button class="confirm" @tap='login'>保存</button>

		
	</view>
</template>

<script>
		import { pathToBase64, base64ToPath } from '../../common/image-tools.js'
export default {
	data() {
		return {
			name:'',
			src:'../../static/cp.jpg',
				src1:'',
			index: 0,
			genderdatas: ['男', '女'],
			gender: '',
			
		};
	},
	onLoad() {
			var that = this;
		that.Net._get('myData',{},(res)=>{
			if(res.code ==1){
			
			   that.name=res.data.username
			    that.src=that.Cfg.Setting.img+res.data.avatar
				 that.src1=res.data.avatar
			}
		});
	},
	methods: {
	login() {
		var that = this;
	     
		
			that.Net._get('upuser',{name:that.name,src:that.src1},(res)=>{
				if(res.code ==1){
				
					that.Msg.Success('提交成功',(res)=>{
					that.Nav._to({url:'/pages/personal/personal',type:2})
					})
				}
			});
			
	},
	openImg1() {
		let me = this;
		
		            //console.log('用户点击确定');
					uni.chooseImage({
						count: 1, //默认9
						
						sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
						sourceType: ['album'], //从相册选择
						success: function(chooseImageRes) {
							const tempFilePaths = chooseImageRes.tempFilePaths
							pathToBase64(tempFilePaths[0])
													.then(base64 => {
													 
														me.Net._post('upAvatara',{avatar:base64},(res)=>{
															if(res.code ==1){
															me.src=me.Cfg.Setting.img+res.data
															me.src1=res.data	
															}
														});
													 })
													 .catch(error => {
													 });
											
						}
					});
		
	
	},
		backPage() {
			uni.navigateBack({});
		},
		gotopage(e) {
			let url = e.currentTarget.dataset.url;
			uni.navigateTo({
				url: url
			});
		},
		openGender: function(e) {
			console.log('picker发送选择改变，携带值为', e.target.value)
			this.index = e.target.value
			this.gender = this.genderdatas[e.target.value];
		},
		
		
	}
};
</script>

<style>
	page{
		padding-top: 1px;
		padding-bottom: 0 !important;
		background-color: #f8f8f8;
	}
	
	.portrait_box{
		width: 100%;
		text-align: center;
		padding: 8vw 0;
	}
	
	.portrait_box image{
		width: 26vw;
		height: 26vw;
		border-radius: 50%;
	}
	
	.set_title{
		width: 90%;
		margin: 0 auto;
		font-size: 4vw;
		color: #4b4b4b;
		font-weight: bold;
		
	}
	
	.list_box{
		width: 90%;
		margin: 0 auto;
		height: 13.5vw;
		display: flex;
		align-items: center;
		border-bottom: 1px solid #e8e8e8;
		box-sizing: border-box;
	}
	
	.list_box .title{
		font-size: 3.5vw;
		color: #999;
		margin-right: 3vw;
		width: 18vw;
	}
	
	.list_box input{
		flex: 1;
		height: 13.5vw;
		line-height: 13.5vw;
		color: #333;
		font-size: 3.5vw;
	}
	
	
	

</style>
